﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script src="~/Content/js/common.js"></script>
<script>
    $(function () {
        $.ajax({
            url: "/ItemsData/GetGridJson",
            data: { itemId: "43445fb8-bbb1-4883-98a2-e4ad0f28a21f" },
            dataType: "json",
            async: false,
            success: function (data) {
                $("#seType").append("<option>选择模板</option>");
                $.each(data, function (i) {
                    $("#seType").append($("<option></option>").val(data[i].F_Id).html(data[i].F_ItemName));
                });
            }
        });
        gridList();
    })

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/templetinfo/GetGridJson",
            height: $(window).height() - 128,
            colModel: [
                { label: '主键', name: 'micro_id', hidden: true },
                { label: '模板名称', name: 'micro_title', width: 100, align: 'left' },
                { label: '模板备注', name: 'remark', width: 150, align: 'left' },
                {   
                    label: '修改时间', name: 'update_time', width: 66, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return (new Date(rowObject.update_time).format("yyyy-MM-dd"));
                    }
                },
                     {
                         label: '是否显示', name: 'is_enable', width: 60, align: 'center',
                         formatter: function (cellvalue, options, rowObject) {
                             if (cellvalue == 1) {
                                 return '显示';
                             } else {
                                 return '不显示';
                             }
                         }
                     }
            ],
            pager: "#gridPager",
            sortname: 'micro_id asc,update_time desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: {
                    keyword: $("#txt_keyword").val(),
                    type: $("#seType").val() == "选择类型" ? "" : $("#seType").val()
                },
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增模板",
            url: "/templetinfo/Form",
            width: "1200px",
            height: "750px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().micro_id;
        $.modalOpen({
            id: "Form",
            title: "修改模板",
            url: "/templetinfo/Form?keyValue=" + keyValue,
            width: "1200px",
            height: "750px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_delete() {
        $.deleteForm({
            url: "/templetinfo/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().micro_id },
            prompt: "注：您确定要删除该项数据吗？",
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_Show() {
        $.deleteForm({
            url: "/templetinfo/Show",
            param: { keyValue: $("#gridList").jqGridRowValue().micro_id },
            prompt: "注：您确定要在手机端显示该模板信息吗？提示：开启之后，手机端模板列表中将显示该模板信息",
            loading: "正在执行操作...",
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_NotShow() {
        $.deleteForm({
            url: "/templetinfo/NotShow",
            param: { keyValue: $("#gridList").jqGridRowValue().micro_id },
            prompt: "注：您确定要在隐藏该模板信息吗？提示：开启之后，手机端模板列表中将隐藏该模板信息",
            loading: "正在执行操作...",
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_details() {
        var keyValue = $("#gridList").jqGridRowValue().micro_id;
        $.modalOpen({
            id: "Details",
            title: "查看模板",
            url: "/templetinfo/Details?keyValue=" + keyValue,
            width: "1200px",
            height: "750px",
            btn: null,
        });
    }
</script>

<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新增模板</a>
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
                <li><a id="NF-edit" authorize="yes" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改模板</a></li>
                <li><a id="NF-delete" authorize="yes" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除模板</a></li>
                <li><a id="NF-Details" authorize="yes" onclick="btn_details()"><i class="fa fa-search-plus"></i>查看</a></li>
                <li class="split"></li>
                <li><a id="NF-disabled" authorize="yes" onclick="btn_Show()"><i class="fa fa-stop-circle"></i>手机端显示</a></li>
                <li><a id="NF-enabled" authorize="yes" onclick="btn_NotShow()"><i class="fa fa-play-circle"></i>手机端不显示</a></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="模板名称" style="width: 200px;" maxlength="25">
                        <select id="seType" name="seType" class="form-control" style="width: 120px;  margin-left: 10px;"></select>
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
